package com.tanhua.locationmanager.controller;

import com.tanhua.domain.db.SurveyDetails;
import com.tanhua.locationmanager.service.PaperService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/paper")
public class PaperController {

    private final PaperService paperService;

    public PaperController(PaperService paperService) {
        this.paperService = paperService;
    }

    @GetMapping(name = "查询所有试卷")
    public ResponseEntity<?> queryPaper(Integer page, Integer pagesize) {
        return paperService.queryPaper(page, pagesize);
    }

    @PostMapping(value = "/savePaper",name = "保存试卷")
    public ResponseEntity<?> savePaper(@RequestBody SurveyDetails surveyDetails) {
        return paperService.savePaper(surveyDetails);
    }

    @RequestMapping(value = "/upload",name = "试卷封面上传")
    public ResponseEntity<?> uploadCover(MultipartFile cover) throws IOException {
        return paperService.uploadCover(cover);
    }

    @GetMapping(value = "/findById/{id}",name = "根据id查询试卷")
    public ResponseEntity<?> queryPaperById(@PathVariable("id") Integer paperId) {
        return paperService.queryPaperById(paperId);
    }

    @PutMapping(name = "更改试卷")
    public ResponseEntity<?> update(@RequestBody SurveyDetails surveyDetails) {
        return paperService.update(surveyDetails);
    }

    @DeleteMapping(value = "/{id}",name = "根据试卷id删除试卷")
    public ResponseEntity<?> delete(@PathVariable("id") Integer paperId){
        return paperService.delete(paperId);
    }
}
